More changes for treesitter support of outline-minor-mode (bug#68824)
authorJuri Linkov <juri@linkov.net>
Tue, 13 Feb 2024 17:02:21 +0000 (19:02 +0200)
committerJuri Linkov <juri@linkov.net>
Tue, 13 Feb 2024 17:02:21 +0000 (19:02 +0200)
* lisp/treesit.el (treesit-outline-level): Set NAMED arg of
'treesit-node-at' to t.  Don't set IGNORE-MISSING arg of
'treesit-node-match-p' to t.

* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
Add "singleton_method" to 'treesit-thing-settings'.
Set 'treesit-outline-predicate'.  Kill local variables
'outline-regexp' and 'outline-level'.

lisp/progmodes/ruby-ts-mode.el
lisp/treesit.el

index 598eaa461fffe1544ad933963bd511e891ec921b..426ae248cac420da642486a7af51daa85f65f060 100644 (file)
@@ -1133,6 +1133,7 @@ leading double colon is not added."
                                 "singleton_class"
                                 "module"
                                 "method"
+                                "singleton_method"
                                 "array"
                                 "hash"
                                 "parenthesized_statements"
@@ -1178,6 +1179,19 @@ leading double colon is not added."
   ;; Imenu.
   (setq-local imenu-create-index-function #'ruby-ts--imenu)
 
+  ;; Outline minor mode.
+  (setq-local treesit-outline-predicate
+              (rx bos (or "singleton_method"
+                          "method"
+                          "alias"
+                          "class"
+                          "module")
+                  eos))
+  ;; Restore default values of outline variables
+  ;; to use `treesit-outline-predicate'.
+  (kill-local-variable 'outline-regexp)
+  (kill-local-variable 'outline-level)
+
   (setq-local treesit-simple-indent-rules (ruby-ts--indent-rules))
 
   ;; Font-lock.
index 25ac582276b28d16acfb2b5937f1da05d27ae0c9..f811b8090bc1cb9332889af20e0cf8fdd1038265 100644 (file)
@@ -2918,8 +2918,8 @@ See the descriptions of arguments in `outline-search-function'."
 
 (defun treesit-outline-level ()
   "Return the depth of the current outline heading."
-  (let* ((node (treesit-node-at (point)))
-         (level (if (treesit-node-match-p node treesit-outline-predicate t)
+  (let* ((node (treesit-node-at (point) nil t))
+         (level (if (treesit-node-match-p node treesit-outline-predicate)
                     1 0)))
     (while (setq node (treesit-parent-until node treesit-outline-predicate))
       (setq level (1+ level)))